<?php

/**
 * Description of IndexController
 *
 * @author Pedro Giacometto
 */
require_once 'Zend/Controller/Action.php';
require_once 'models/UsuarioModelo.php';

class IndexController extends Zend_Controller_Action
{
    private $_usuarioModelo;
    private $_config;

    public function init()
    {
        $this->_usuarioModelo = new UsuarioModelo();
        $this->_config = Zend_Registry::get('config');        
       
    }

    public function indexAction()
    {
      
        $this->render();
    }

    public function listAction()
    {
        $this->view->subtitulo = $this->_config->parametros->subTituloActionList;
        $this->view->usuarios = $this->_usuarioModelo->obtenerTodos();
        $this->render();
    }

    public function verAction()
    {
        $this->view->subtitulo = $this->_config->parametros->subTituloActionVer;
        $request = $this->getRequest();
        $id = $request->getParam('id');
        if ($id) {        
            $result = $this->_usuarioModelo->obtenerPorId($id);
            $this->view->usuario = $result;
            $this->render();
        } else {
            return $this->_redirect('index/list');
        }
    }

    public function buscarAction()
    {
        $request = $this->getRequest();
        $nombre = $request->getParam('nombre');
        if ($nombre) {         
            $result = $this->_usuarioModelo->buscarPorNombre($nombre);
            $this->view->busqueda = $nombre;
            $this->view->usuarios = $result;

            $this->render();
        } else {
            return $this->_redirect('index/list');
        }
    }

    public function holaAction()
    {
        $this->view->titulo = "Holla";
        $this->view->doctype('XHTML1_STRICT');
        $this->view->headTitle('My First Zend Framework Application');

        $this->render();
    }

    //put your code here
}

